package com.ybxx.asset.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.dao.BuildingDao;
import com.ybxx.asset.model.Building;
import com.ybxx.asset.model.Instrument;
import com.ybxx.asset.service.BuildingService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;

public class BuildingServiceImpl extends BaseServiceImpl<Building> implements
		BuildingService {
	private BuildingDao buildingDao;
	public BuildingServiceImpl(BuildingDao dao) {
		super(dao);
		this.buildingDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<Building> queryPage(Building building, QueryFilter filter) {
		String hql="from Building b where 1=1 ";
		if(building!=null && StringUtils.isNotEmpty(building.getQzbh())){
			hql+=" and b.qzbh like '%"+building.getQzbh()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getBname())){
			hql+=" and b.bname like '%"+building.getBname()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getStruct())){
			hql+=" and b.struct like '%"+building.getStruct()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getMdept())){
			hql+=" and b.mdept like '%"+building.getMdept()+"%'";
		}
		
		return buildingDao.findByHql(hql, null, filter.getPagingBean());
	}
	public List<Building> exportExcel_Print(Building building) {
		String hql="from Building b left join fetch b.company c where 1=1 ";
		if(building!=null && StringUtils.isNotEmpty(building.getQzbh())){
			hql+=" and b.qzbh like '%"+building.getQzbh()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getBname())){
			hql+=" and b.bname like '%"+building.getBname()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getStruct())){
			hql+=" and b.struct like '%"+building.getStruct()+"%'";
		}
		if(building!=null && StringUtils.isNotEmpty(building.getMdept())){
			hql+=" and b.mdept like '%"+building.getMdept()+"%'";
		}
		
		return buildingDao.findByHql(hql, null);
	}
	@Override
	public Building get(String id) {
		String hql="from Building b left join fetch b.company c where bid='"+id+"' ";
		return (Building)buildingDao.findUnique(hql, null);
	}
}
